﻿using EyFramework.ORM;
using Ncov2019.Entity;
using System.Collections.Generic;

namespace Ncov2019.Core.Dao
{
    /// <summary>
    ///  NCOV_USERS表的数据库操作
    /// </summary>
    public class NcovUsersDao : BaseDaoHis<NcovUsers>, INcovUsersDao
    {
        public bool AbandonUser(NcovUsers ncovUser)
        {
            return Db.Updateable<NcovUsers>().UpdateColumns(it => new NcovUsers() { DC_FLAG = "1" }).Where(it => it.PAT_SEQ == ncovUser.PAT_SEQ).ExecuteCommand() > 0;
        }

        public List<NcovUsers> GetUsersByCompany(string company)
        {
            return Db.Queryable<NcovUsers>().Where(p => p.COMPANY == company).ToList();
        }

        public bool ImportUsers(List<NcovUsers> ncovUsers)
        {
            return true;
        }

        public List<NcovUsersDto> QueryBy(NcovUsersParam queryParam)
        {
            return Db.Queryable<NcovUsersDto>()
                .WhereIF(!string.IsNullOrEmpty(queryParam.CHT_ID), it => it.CHT_ID.StartsWith(queryParam.CHT_ID))
                .WhereIF(!string.IsNullOrEmpty(queryParam.PAT_NM), it => it.PAT_NM.StartsWith(queryParam.PAT_NM))
                .WhereIF(queryParam.DC_FLAG != "Y", it => it.DC_FLAG != "1")
                .WhereIF(!string.IsNullOrEmpty(queryParam.PAT_TYPE), it => it.PAT_TYPE == queryParam.PAT_TYPE)
                .ToList();
        }
    }
}